package com.cheng.sell.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @description: 手动获取openid
 * @author: 程新涛
 * @create: 2018-09-16 16:48
 */
@RestController
@RequestMapping("/weixin")
@Slf4j
public class WeixinController {

    @GetMapping("/auth")
    public void auth(@RequestParam("code") String code) {
        log.info("进入auth方法");
        log.info("code的值是{}", code);
        String url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=wxe352100b061fcfdb&secret=2ef0260a2d3bb85b585b0f8c0332ade6&code=" + code + "&grant_type=authorization_code";
        RestTemplate restTemplate = new RestTemplate();
        String result = restTemplate.getForObject(url, String.class);
        log.info(result);
    }
}
